package com.sbc.liteflow.config;

import cn.hutool.core.thread.ThreadFactoryBuilder;
import com.yomahub.liteflow.thread.ExecutorBuilder;

import java.util.concurrent.*;

/**
 * @Description: 自定义线程池
 * @Author: songbaicheng
 * @Create: 2024/11/30 14:12
 **/
public class CustomThreadExecutor implements ExecutorBuilder {

    /**
     * 线程池配置
     */
    int corePoolSize = 4;
    /**
     * 线程池最大线程数
     */
    int maxPoolSize = 8;
    /**
     * 线程池缓冲队列容量
     */
    int queueCapacity = 10;
    /**
     * 线程池缓冲队列等待时间
     */
    long keepAliveTime = 90;

    @Override
    public ExecutorService buildExecutor() {
        return new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, TimeUnit.SECONDS, new LinkedBlockingQueue<>(queueCapacity), ThreadFactoryBuilder.create().setNamePrefix("liteflow-thread-").build(), new ThreadPoolExecutor.DiscardPolicy());
    }
}
